package in.hitmedia.test.stack;
import java.util.Stack; 

public class StackSorting 
{


	@SuppressWarnings("boxing")
	private static void insert(Stack<Integer> s, Integer i)
	{
		if (s.empty() || s.peek() <= i)
		{
			s.push(i);
		}
		else
		{
			Integer f = s.pop();
			insert(s, i);
			s.push(f);
		}
	}

	public static void sort(Stack<Integer> s)
	{
		if (!s.empty())
		{
			Integer e = s.pop();
			sort(s);
			insert(s, e);
		}
	}
	
	
	
	
	@SuppressWarnings("boxing")
	public static void main(String args[])
	{
		Stack<Integer> s = new Stack<Integer>();
		
		s.push(11);
		s.push(19);
		s.push(15);
		s.push(5);
		s.push(23);
		s.push(8);
		
		System.out.println(s);
		
		sort(s);
		
		System.out.println(s);
		
	}
}
